package net.comm.group.db;

import org.sakaiproject.db.api.iServiceSql;


/**
 * methods for accessing user data in a database.
 */
public class GsignupServiceSqlMysql implements iServiceSql
{
	/**
	 * 返回根据主键删除语句
	 */
	public String getDeleteSql()
	{
		return "delete from Gsignup" +
				" where PartyID=? and UserID=?";
	}

	/**
	 * 返回根据主键删除语句
	 */
	public String getDelbyPartyIDSql()
	{
		return "delete from Gsignup" +
				" where PartyID=? ";
	}

	/**
	 * 返回插入语句
	 */
	public String getInsertSql()
	{
		return "insert into Gsignup " +
				" (  partyID,  userID,  signDate )" +
				" values (?,?,?)";
	}
	
	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdateSql()
	{
		return "update Gsignup" +
				"  set  signDate=? " +
				"  where PartyID=? and UserID=?";
	}

	/**
	 * 返回根据主键查询语句
	 */
	public String getbykeySql()
	{
		return "select partyID,  userID,  signDate" +
				" from Gsignup" +
				" where PartyID=? and UserID=?";
	}
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakaiuseridmap table.
	 */
	public String getRecbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select partyID, userID,  signDate " +
				" from Gsignup");
		
		sb.append(" where partyID=? ");
		sb.append(" limit ?, ?");
				
		return sb.toString();	
	}	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakaiuseridmap table.
	 */
	public String getRecSql()
	{
	
		StringBuffer sb =  new StringBuffer("select partyID, userID,  signDate " +
				" from Gsignup ");
		return sb.toString();	
	}	
	
	/**
	 * 返回根据会员ID查询语句 
	 */
	public String getByUserIDSql()
	{
		StringBuffer sb =  new StringBuffer("select partyID,  userID,  signDate " +
				" from Gsignup");
		
		sb.append(" where GroupID in ( select GroupID from GMember where UserID=? )" +
				" and MTime >= ? group by GroupID Order by MTime desc ");
				
		return sb.toString();
	}	
	/**
	 * 返回所有记录数
	 */
	public String getCountSql1()
	{
		return "select count(*) as COUNT from Gsignup";
	}

	/**
	 * 返回根据查询条件的记录数
	 */
	public String getCountSql3()
	{
		return "select count(*) as COUNT from Gsignup" +
				" where partyID=?  ";
	}
	/**
	 * @see net.comm.job.db.iServiceSql.impl.GsignuperviceSql#getMaxInputsForSelectWhereInQueries()
	 */
	public int getMaxInputsForSelectWhereInQueries() {
		// For Oracle, the maximum supported number of expressions in a list is 1000. 
		return 1000;
	}
}
